local s = require "service"
local game_cmd = require "cmd_def"
local skynet = require "skynet"
local table_utils = require "table_utils"

s.fight = {}

s.fight.fight_obj = function(dest_uid, target_player_ids, skill_id)
    if table_utils.size(target_player_ids) <= 0 then
        return
    end

    local extra_msg = table.concat(target_player_ids, ",")
    local response = {
        error_code = game_cmd.ERROR_CODE.SUCCESS,
        uid = dest_uid,
        target_uid = 0,
        skill_id = skill_id,
        json_data = extra_msg,
    }
    for _, uid in pairs(target_player_ids) do
        response.target_uid = uid
        local scene_player = s.uid2player[uid]
        if scene_player then
            skynet.send(scene_player:get_gate(), "lua", "send", uid, game_cmd.SERVER_CMD.USE_SKILL_RESPONSE, response)
        end
    end

    local scene_player = s.uid2player[dest_uid]
    if not scene_player then
        return
    end
    response.target_uid = 0
    skynet.send(scene_player:get_gate(), "lua", "send", dest_uid, game_cmd.SERVER_CMD.USE_SKILL_RESPONSE, response)
end
